package cn.net.autocode.platform.function;

import cn.net.autocode.core.bean.ResultT;
import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.platform.function.service.FuncServ;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("platformFuncInfo")
@RequestMapping("/platform/funcInfo")
public class FuncInfo {
    private final Dao dictDao;

    private final FuncServ funcServ;

    public FuncInfo(@Qualifier("dictDao") Dao dictDao, FuncServ funcServ) {
        this.dictDao = dictDao;
        this.funcServ = funcServ;
    }

    @RequestMapping("load")
    public ResultT load(@RequestBody JSONObject param){
        JSONObject json = dictDao.queryJSON("select * from ac_page where id=?",param.getString("id"));
        return ResultT.success(json);
    }


    @RequestMapping("pageRelease")
    public ResultT pageRelease(@RequestBody JSONObject param){
        String info = funcServ.pageRelease(param);
        if(info.startsWith("success:")){
            info = info.replace("success:","");
            if (info.isBlank()){
                return ResultT.success();
            }else{
                JSONObject rs = new JSONObject();
                rs.put("msg",info);
                return ResultT.success(rs);
            }
        }else{
            info = info.replace("fail:","");
            return ResultT.fail(info);
        }
    }

    @RequestMapping("getReleaseVersion")
    public ResultT getReleaseVersion(@RequestBody JSONObject param){
        funcServ.getReleaseVersion(param.getString("id"));
        return ResultT.success();
    }
}
